package acs.offer.httpclient;

import acs.offer.client.ClientHandler;
import acs.offer.util.OfferDecoder;
import acs.offer.util.OfferEncoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;

public class HttpClientInitializer  extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();

        // 添加编解码器, 由于ByteToMessageDecoder的子类无法使用@Sharable注解,
        // 这里必须给每个Handler都添加一个独立的Decoder.
        pipeline.addLast(new OfferEncoder());
        pipeline.addLast(new OfferDecoder());

        // and then business logic.
        pipeline.addLast(new ClientHandler());
    }
}
